package com.youcheng.utils;

import com.youcheng.constant.ErrorTips;
import org.springframework.lang.Nullable;

public class ApiResponse {

    private  int code;
    private  String message;
    private  Object data;

    public ApiResponse() {
    }

    public ApiResponse(int code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static ApiResponse success(String message , int code , @Nullable Object data){
        return new ApiResponse(code,message,data);
    }

    public static ApiResponse success(){
        return new ApiResponse(ErrorTips.commonSuccessCode,"success",null);
    }

    public static ApiResponse success(@Nullable Object data){
        return new ApiResponse(ErrorTips.commonSuccessCode,"success",data);
    }


    public static ApiResponse error(int code, String message){
        return new ApiResponse(code,message,null);
    }

    public static ApiResponse error(String message){
        return new ApiResponse(ErrorTips.commonErrorCode,message,null);
    }

    public static ApiResponse error(int code, String message ,Object data){
        return new ApiResponse(code,message,data);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
